Reading Category Samples PRO
The Scripting app provides access to category-based health data using the global function Health.queryCategorySamples(). Category samples represent health-related events or states with a start date, end date, and a discrete value — such as sleep stages, mindful sessions, menstrual flow, and ovulation test results.
This guide explains how to query, interpret, and use category samples in your scripts.
What Is a Category Sample?
A category sample includes:
type: The category data type (e.g.,"sleepAnalysis","mindfulSession")startDate/endDate: The time interval the event occurredvalue: An integer representing a state, mapped from an enummetadata: Optional additional info
Examples:
"sleepAnalysis"with valueasleepCore,awake, orinBed"menstrualFlow"with valuemild,moderate, orsevere
API Overview
Parameters
Example: Reading Sleep Analysis Samples
You can map the value to an enum like this:
Example: Reading Mindful Session Events
Notes
- All returned items are instances of
HealthCategorySample - The
.valuefield is numeric and should be interpreted using the appropriate enum - You can access optional
.metadatafor extra context if available - Category data is ideal for modeling sleep, mental wellness, reproductive health, and symptoms
Summary
To read category samples:
- Use
Health.queryCategorySamples(categoryType, options) - Filter by date, sort, and limit as needed
- Map
.valueto the correct enum for human-readable interpretation
This API gives you structured access to event-based health records in HealthKit.
